<?php

namespace App\Http\Controllers\Applet\Payment;

use App\Exceptions\PaymentException;
use App\Exceptions\SponsorException;
use App\Services\Applet\Payment\PaymentService;
use Exception;
use Illuminate\Http\JsonResponse;

class PaymentController extends BasePaymentController
{

    protected PaymentService $paymentService;

    /**
     * @throws Exception
     */
    public function __construct()
    {
        parent::__construct();
        $this->paymentService = $this->loadService('Applet\Payment\PaymentService');
    }

    /**
     * 获取支付参数
     * @return JsonResponse
     * @throws PaymentException|SponsorException
     */
    public function payParams(): JsonResponse
    {
        $rule = [
            'orderNo' => 'required|string|size:32',
            'orderType' => 'required|integer|in:10,20,30',
            'payType' => 'required|integer|in:10,20',
            'platform' => 'required|integer|in:10,20,30',
        ];

        if ($this->ruleCheck($rule)) {
            return outputJsonError();
        }

        $data = $this->paymentService->payParams($this->params);
        return outputJsonResult($data);
    }

}
